const arr = [3, 2, 1, 3, 1, 2, 3, 5, 5, 4, 3, 6, 5, 4, 7, 3];

// console.log(Math.max(...arr));

// console.log(arr.reduce((c, n) => Math.max(c, n)));

// const arrMap = arr.map((ele, index, arr) => {
//   return ele * 2;
// });
// console.log(arrMap);

// // 用reduce实现map
// Array.prototype.reduceToMap = function (handle) {
//   return this.reduce((target, current, index) => {
//     target.push(handle.call(this, current, index, this));
//     return target;
//   }, []);
// };
// console.log(
//   arr.reduceToMap((ele, index, arr) => {
//     return ele * 2;
//   })
// );

console.log(arr.filter((i) => i === 3));

// 用reduce实现filter
Array.prototype.reduceToFilter = function (handle) {
  return this.reduce((target, current, index) => {
    if (handle.call(this, current, index, this)) {
      target.push(current)
    }
    return target;
  }, []);
};

console.log(arr.reduceToFilter((i) => i === 3));